package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.CustomBean;
import com.project.bean.LogBean;
import com.project.service.ICustomService;
import com.project.service.ILogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("custom")
@Api(tags = "客户控制层")
public class CustomController {
    @Autowired
    private ICustomService customService;
    @ApiOperation("动态条件分页查询客户")
    @GetMapping("findByItem")
    public IPage<CustomBean> findByItem(Integer pageNO, String customName, String scope){
        return customService.findByItem(pageNO,customName,scope);
    }

    @ApiOperation("根据客户id查询客户")
    @GetMapping("findById")
    public CustomBean findById(Integer customId){
        return customService.findById(customId);
    }

    @ApiOperation("通过id修改负责人和电话")
    @PutMapping("updateById")
        public String updateById(Integer customId, String newHead, String newPhone, String newScope){
        customService.updateById(customId, newHead, newPhone, newScope);
        return "ok";
    }

    @ApiOperation("根据名称查客户")
    @GetMapping("findByName")
    public String findByName(String name) {
        if(customService.findByName(name)==null){
            return "no";
        }else {
            return "ok";
        }
    }

    @ApiOperation("添加客户")
    @PostMapping("add")
    public String add(@RequestBody CustomBean customBean){
        customService.add(customBean);
        return "ok";
    }

    @ApiOperation("查询所有客户")
    @GetMapping("findAll")
    public List<CustomBean> findAll(){
        return customService.findAll();
    }

}
